/*
 * @Author: sympsel sympsel@outlook.com
 * @Date: 2025-09-23 08:19:26
 * @LastEditors: sympsel sympsel@outlook.com
 * @LastEditTime: 2025-09-28 08:16:52
 * @FilePath: \.vscoded:\Code\vsCode\c++\work25_9_23\src\test.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

#include <iostream>
#include "List.h"

void test1() {
    std::cout << "=== Test 1: Basic Functionality Test ===" << std::endl;
    List<int> list;
    for (int i = 0; i < 15; ++i) {
        list.append(i + 1);
    }
    std::cout << "After adding 15 elements: " << list << std::endl;
    std::cout << "Current size: " << list.size() << std::endl;
    std::cout << "Current capacity: " << list.capacity() << std::endl;
    
    list.clear();
    std::cout << "After clear: " << list << std::endl;
    std::cout << "Size after clear: " << list.size() << std::endl;
    std::cout << "Capacity after clear: " << list.capacity() << std::endl;
    std::cout << "Is empty: " << (list.empty() ? "Yes" : "No") << std::endl;
}

void test2() {
    std::cout << "\n=== Test 2: Remove Operations Test ===" << std::endl;
    List<int> list;
    for (int i = 0; i < 15; ++i) {
        list.append(i + 1);
    }
    std::cout << "Initial list: " << list << std::endl;
    
    list.remove();  // Remove last element
    std::cout << "After removing last: " << list << std::endl;
    
    list.removeFirst();  // Remove first element
    std::cout << "After removing first: " << list << std::endl;
    
    list.remove(1);  // Remove element at index 1
    std::cout << "After removing index 1: " << list << std::endl;
    
    list.remove(list.size() - 1);  // Remove last element
    std::cout << "After removing last: " << list << std::endl;
    
    std::cout << "Index 1: " << list.indexAt(1) 
              << ", Index 0: " << list.indexAt(0) 
              << ", Last element: " << list.indexAt(list.size() - 1) << std::endl;
}

void test3() {
    std::cout << "\n=== Test 3: Insert Operations Test ===" << std::endl;
    List<int> list;
    
    // Insert at head
    list.insert(100);
    list.insert(200);
    std::cout << "After inserting 2 elements at head: " << list << std::endl;
    
    // Insert at specific position
    list.insert(300, 1);
    std::cout << "After inserting 300 at index 1: " << list << std::endl;
    
    // Continue adding to test capacity expansion
    for (int i = 0; i < 10; ++i) {
        list.append(400 + i);
    }
    std::cout << "After adding 10 more elements: " << list << std::endl;
    std::cout << "Current size: " << list.size() << std::endl;
    std::cout << "Current capacity: " << list.capacity() << std::endl;
}

void test4() {
    std::cout << "\n=== Test 4: Copy Constructor and Assignment Test ===" << std::endl;
    List<int> list1;
    for (int i = 0; i < 5; ++i) {
        list1.append(i * 10);
    }
    std::cout << "list1: " << list1 << std::endl;
    
    // Copy constructor
    List<int> list2(list1);
    std::cout << "Copy constructed list2: " << list2 << std::endl;
    
    // Assignment operator
    List<int> list3;
    list3 = list1;
    std::cout << "Assigned list3: " << list3 << std::endl;
    
    // Modify original list to verify deep copy
    list1.append(999);
    std::cout << "Modified list1: " << list1 << std::endl;
    std::cout << "list2 (should be unchanged): " << list2 << std::endl;
    std::cout << "list3 (should be unchanged): " << list3 << std::endl;
}

void test5() {
    std::cout << "\n=== Test 5: Exception Handling Test ===" << std::endl;
    List<int> list;
    
    try {
        list.remove();  // Remove from empty list
    } catch (const std::exception& e) {
        std::cout << "Exception caught: " << e.what() << std::endl;
    }
    
    list.append(1);
    list.append(2);
    
    try {
        std::cout << "Attempting to access index 5: " << list.indexAt(5) << std::endl;
    } catch (const std::exception& e) {
        std::cout << "Exception caught: " << e.what() << std::endl;
    }
    
    try {
        list.insert(100, 5);  // Insert at invalid position
    } catch (const std::exception& e) {
        std::cout << "Exception caught: " << e.what() << std::endl;
    }
}

void test6() {
    std::cout << "\n=== Test 6: String List Test ===" << std::endl;
    List<std::string> strList;
    
    strList.append("Hello");
    strList.append("World");
    strList.insert("Start", 0);
    strList.insert("Middle", 2);
    
    std::cout << "String list: " << strList << std::endl;
    std::cout << "Index 1: " << strList.indexAt(1) << std::endl;
}

void test7() {
    std::cout << "\n=== Test 7: Operator [] Test ===" << std::endl;
    List<int> list;
    for (int i = 0; i < 5; ++i) {
        list.append(i * 2);
    }
    
    std::cout << "Original list: " << list << std::endl;
    
    // Modify elements using []
    list[2] = 999;
    list[0] = 888;
    
    std::cout << "Modified list: " << list << std::endl;
    std::cout << "list[1] = " << list[1] << std::endl;
    std::cout << "list[3] = " << list[3] << std::endl;
}

int main() {
    std::cout << "Starting List class tests..." << std::endl;
    
    test1();  // Basic functionality test
    test2();  // Remove operations test
    test3();  // Insert operations test
    test4();  // Copy constructor and assignment test
    test5();  // Exception handling test
    test6();  // String list test
    test7();  // Operator test
    
    std::cout << "\nAll tests completed!" << std::endl;
    return 0;
}